package util;

import java.sql.*;

public class DBUtil {
    ResultSet rs = null;
    Connection conn = null;
    Statement st = null;
    PreparedStatement ps = null;

    public void getConn() throws Exception {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            String url = "jdbc:oracle:thin:@localhost:1521:orcl";
            String user = "user01";
            String password = "123456";
            //创建连接
            conn = DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    //释放连接,先开后关
    public void closeConn() {
        try {
            if (rs != null)
                rs.close();
            if (st != null)
                st.close();
            if (ps != null)
                ps.close();
            if (conn != null)
                conn.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}